/**
 * Created with IntelliJ IDEA.
 * User: Yura
 * Date: 20.09.13
 * Time: 15:20
 * To change this template use File | Settings | File Templates.
 */
package kpi.training.palindrome;
import java.util.*;


/**
 *  Class for searching substring-palindromes
 */
public class Palindrome
{
    public static void main(String[] arg)
    {
        Scanner scan = new Scanner(System.in);
        String originalString = getStringFrom(scan);

        String[] arrayOfSubstringPalindromes = getAllPalindromesFrom(originalString);

        printElementsFrom(arrayOfSubstringPalindromes);
    }

    /**
     *  @return true if testedString is palindrome, otherwise false
     */
    public static boolean isStringIsPalindrome(String testedString)
    {
        StringBuilder auxiliaryString = new StringBuilder(testedString);   /* we use auxiliaryString to make reverse string of testedString */
        return(testedString.equals(auxiliaryString.reverse().toString()));
    }

    public static String getStringFrom(Scanner input)
    {
        return input.nextLine();
    }

    /**
     *   Method looks for substring-palindromes in original string.
     *   @return arrayOfSubstringPalindromes - array of palindromes without empty elements
     */
    public static String[] getAllPalindromesFrom(String originalString)
    {
        int lengthOfOriginalString = originalString.length();
        int minimalSizeOfSubstring = 3;
        List<String> listOfSubstringPalindromes = new ArrayList<String>();
        for (int currentLength = minimalSizeOfSubstring; currentLength <= lengthOfOriginalString; currentLength++)    /* currentLength - size of substring */
        {
            for (int beginOfSubstring = 0; beginOfSubstring <= lengthOfOriginalString - currentLength; beginOfSubstring++)  /* beginOfSubstring means begin index in original string */
            {
                String subString = originalString.substring(beginOfSubstring, beginOfSubstring + currentLength);
                if (isStringIsPalindrome(subString))
                {
                    listOfSubstringPalindromes.add(subString);
                }
            }
        }
        String[] arrayOfSubstringPalindromes = new String[listOfSubstringPalindromes.size()];
        listOfSubstringPalindromes.toArray(arrayOfSubstringPalindromes);
        return arrayOfSubstringPalindromes;
    }

    public static void printElementsFrom(String[] array)
    {
        for (String element:array)
        {
            System.out.println(element);
        }
    }
}